package com.wuqing.consumer.controller;

import com.wuqing.consumer.service.TpService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author wuqing
 * @date 2020/8/6
 */
@RestController
@RequestMapping("tp")
public class TpController {

    @Resource
    private TpService tpService;

    @RequestMapping("/go")
    @ResponseBody
    public String go(@RequestParam String name) {
        long start = System.currentTimeMillis();
        //5分钟
        while (System.currentTimeMillis() - start <= 5 * 60 * 1000) {

            try {
                TimeUnit.MILLISECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            tpService.go(name);
        }
        return "finish";
    }

}